<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属科室" prop="docDept">
        <el-input
          v-model="queryParams.docDept"
          placeholder="请输入所属科室"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第一科室" prop="docDept1">
        <el-input
          v-model="queryParams.docDept1"
          placeholder="请输入第一科室"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="级别" prop="docLevel">
        <el-input
          v-model="queryParams.docLevel"
          placeholder="请输入级别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医生姓名" prop="docName">
        <el-input
          v-model="queryParams.docName"
          placeholder="请输入医生姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期天上午(0：无班 1：有班)" prop="day0am">
        <el-input
          v-model="queryParams.day0am"
          placeholder="请输入星期天上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期天下午(0：无班 1：有班)" prop="day0pm">
        <el-input
          v-model="queryParams.day0pm"
          placeholder="请输入星期天下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期一上午(0：无班 1：有班)" prop="day1am">
        <el-input
          v-model="queryParams.day1am"
          placeholder="请输入星期一上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期一下午(0：无班 1：有班)" prop="day1pm">
        <el-input
          v-model="queryParams.day1pm"
          placeholder="请输入星期一下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期二上午(0：无班 1：有班)" prop="day2am">
        <el-input
          v-model="queryParams.day2am"
          placeholder="请输入星期二上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期二下午(0：无班 1：有班)" prop="day2pm">
        <el-input
          v-model="queryParams.day2pm"
          placeholder="请输入星期二下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期三上午(0：无班 1：有班)" prop="day3am">
        <el-input
          v-model="queryParams.day3am"
          placeholder="请输入星期三上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期三下午(0：无班 1：有班)" prop="day3pm">
        <el-input
          v-model="queryParams.day3pm"
          placeholder="请输入星期三下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期四上午(0：无班 1：有班)" prop="day4am">
        <el-input
          v-model="queryParams.day4am"
          placeholder="请输入星期四上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期四下午(0：无班 1：有班)" prop="day4pm">
        <el-input
          v-model="queryParams.day4pm"
          placeholder="请输入星期四下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期五上午(0：无班 1：有班)" prop="day5am">
        <el-input
          v-model="queryParams.day5am"
          placeholder="请输入星期五上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期五下午(0：无班 1：有班)" prop="day5pm">
        <el-input
          v-model="queryParams.day5pm"
          placeholder="请输入星期五下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期六上午(0：无班 1：有班)" prop="day6am">
        <el-input
          v-model="queryParams.day6am"
          placeholder="请输入星期六上午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="星期六下午(0：无班 1：有班)" prop="day6pm">
        <el-input
          v-model="queryParams.day6pm"
          placeholder="请输入星期六下午(0：无班 1：有班)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['doclist:docList:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['doclist:docList:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['doclist:docList:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['doclist:docList:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="docListList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医生ID" align="center" prop="docId" />
      <el-table-column label="所属科室" align="center" prop="docDept" />
      <el-table-column label="第一科室" align="center" prop="docDept1" />
      <el-table-column label="级别" align="center" prop="docLevel" />
      <el-table-column label="医生姓名" align="center" prop="docName" />
      <el-table-column label="星期天上午(0：无班 1：有班)" align="center" prop="day0am" />
      <el-table-column label="星期天下午(0：无班 1：有班)" align="center" prop="day0pm" />
      <el-table-column label="星期一上午(0：无班 1：有班)" align="center" prop="day1am" />
      <el-table-column label="星期一下午(0：无班 1：有班)" align="center" prop="day1pm" />
      <el-table-column label="星期二上午(0：无班 1：有班)" align="center" prop="day2am" />
      <el-table-column label="星期二下午(0：无班 1：有班)" align="center" prop="day2pm" />
      <el-table-column label="星期三上午(0：无班 1：有班)" align="center" prop="day3am" />
      <el-table-column label="星期三下午(0：无班 1：有班)" align="center" prop="day3pm" />
      <el-table-column label="星期四上午(0：无班 1：有班)" align="center" prop="day4am" />
      <el-table-column label="星期四下午(0：无班 1：有班)" align="center" prop="day4pm" />
      <el-table-column label="星期五上午(0：无班 1：有班)" align="center" prop="day5am" />
      <el-table-column label="星期五下午(0：无班 1：有班)" align="center" prop="day5pm" />
      <el-table-column label="星期六上午(0：无班 1：有班)" align="center" prop="day6am" />
      <el-table-column label="星期六下午(0：无班 1：有班)" align="center" prop="day6pm" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['doclist:docList:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['doclist:docList:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改医生表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属科室" prop="docDept">
          <el-input v-model="form.docDept" placeholder="请输入所属科室" />
        </el-form-item>
        <el-form-item label="第一科室" prop="docDept1">
          <el-input v-model="form.docDept1" placeholder="请输入第一科室" />
        </el-form-item>
        <el-form-item label="级别" prop="docLevel">
          <el-input v-model="form.docLevel" placeholder="请输入级别" />
        </el-form-item>
        <el-form-item label="医生姓名" prop="docName">
          <el-input v-model="form.docName" placeholder="请输入医生姓名" />
        </el-form-item>
        <el-form-item label="星期天上午(0：无班 1：有班)" prop="day0am">
          <el-input v-model="form.day0am" placeholder="请输入星期天上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期天下午(0：无班 1：有班)" prop="day0pm">
          <el-input v-model="form.day0pm" placeholder="请输入星期天下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期一上午(0：无班 1：有班)" prop="day1am">
          <el-input v-model="form.day1am" placeholder="请输入星期一上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期一下午(0：无班 1：有班)" prop="day1pm">
          <el-input v-model="form.day1pm" placeholder="请输入星期一下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期二上午(0：无班 1：有班)" prop="day2am">
          <el-input v-model="form.day2am" placeholder="请输入星期二上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期二下午(0：无班 1：有班)" prop="day2pm">
          <el-input v-model="form.day2pm" placeholder="请输入星期二下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期三上午(0：无班 1：有班)" prop="day3am">
          <el-input v-model="form.day3am" placeholder="请输入星期三上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期三下午(0：无班 1：有班)" prop="day3pm">
          <el-input v-model="form.day3pm" placeholder="请输入星期三下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期四上午(0：无班 1：有班)" prop="day4am">
          <el-input v-model="form.day4am" placeholder="请输入星期四上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期四下午(0：无班 1：有班)" prop="day4pm">
          <el-input v-model="form.day4pm" placeholder="请输入星期四下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期五上午(0：无班 1：有班)" prop="day5am">
          <el-input v-model="form.day5am" placeholder="请输入星期五上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期五下午(0：无班 1：有班)" prop="day5pm">
          <el-input v-model="form.day5pm" placeholder="请输入星期五下午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期六上午(0：无班 1：有班)" prop="day6am">
          <el-input v-model="form.day6am" placeholder="请输入星期六上午(0：无班 1：有班)" />
        </el-form-item>
        <el-form-item label="星期六下午(0：无班 1：有班)" prop="day6pm">
          <el-input v-model="form.day6pm" placeholder="请输入星期六下午(0：无班 1：有班)" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDocList, getDocList, delDocList, addDocList, updateDocList } from "@/api/doclist/docList";

export default {
  name: "DocList",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生表表格数据
      docListList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        docDept: null,
        docDept1: null,
        docLevel: null,
        docName: null,
        day0am: null,
        day0pm: null,
        day1am: null,
        day1pm: null,
        day2am: null,
        day2pm: null,
        day3am: null,
        day3pm: null,
        day4am: null,
        day4pm: null,
        day5am: null,
        day5pm: null,
        day6am: null,
        day6pm: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询医生表列表 */
    getList() {
      this.loading = true;
      listDocList(this.queryParams).then(response => {
        this.docListList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        docId: null,
        docDept: null,
        docDept1: null,
        docLevel: null,
        docName: null,
        day0am: null,
        day0pm: null,
        day1am: null,
        day1pm: null,
        day2am: null,
        day2pm: null,
        day3am: null,
        day3pm: null,
        day4am: null,
        day4pm: null,
        day5am: null,
        day5pm: null,
        day6am: null,
        day6pm: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.docId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医生表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const docId = row.docId || this.ids
      getDocList(docId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改医生表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.docId != null) {
            updateDocList(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDocList(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const docIds = row.docId || this.ids;
      this.$modal.confirm('是否确认删除医生表编号为"' + docIds + '"的数据项？').then(function() {
        return delDocList(docIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('doclist/docList/export', {
        ...this.queryParams
      }, `docList_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
